package com.qf.listener;

import com.event.EventListener;
import com.qf.service.CouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class CouponGetListener implements EventListener<Map> {

    @Autowired
    private CouponService couponService;

    @Override
    public String eventType() {
        return "coupon_get";
    }

    @Override
    public void eventHandler(Map map) {
        System.out.println("接收到优惠券抢劵的消息：" + map);
        Integer uid = (Integer) map.get("uid");//用户id
        Integer cid = (Integer) map.get("cid");//优惠券id

        //修改优惠券的库存
        //生成领取记录
        couponService.updateCouponNumber(cid, uid);
    }
}
